package test.testcase.dao;

import test.utils.GetValue;
import test.utils.JsonResult;
import test.utils.Mysql;

public class CaseCountDao {
	
	public static JsonResult getCaseCountlimit(String limit, String projectid) {
		return Mysql.select("select * from casecount where projectid="+projectid+" order by date desc limit "+limit);
	}
	
	public static void casecount() {
		String today = GetValue.getDateStr(0);
		String yestaday = GetValue.getDateStr(-1);
        Mysql.excute("INSERT INTO casecount SELECT '"+yestaday+"' AS `date`,COUNT(*) AS `count`,projectid FROM testcase a WHERE a.`inserttime`<'"+today+"' group by a.projectid");
	}
	
	public static JsonResult tongji(String projectid) {
		return Mysql.select("SELECT COUNT(*) as count FROM `testcase` WHERE projectid="+projectid+" AND last_excute_result IN ('失败','异常') " + 
				"UNION ALL \r\n" + 
				"SELECT COUNT(*) as count FROM testcase where projectid=" + projectid +" " +
				"UNION ALL \r\n" + 
				"SELECT COUNT(*) as count FROM testcase WHERE last_excute_result='通过' and projectid=" + projectid);
	}

}
